package pathFinding;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import Model.Case;
import Model.Plateau;

public class PathFindingBasic implements PathFinding {
	
	Plateau plateau ;
	
	public PathFindingBasic(Plateau p) {
		plateau = p;
	}
	
	@Override
	public void ajouterTrajet(Trajet t) {
		//nothing todo here
	}
	
	@Override
	public List<Case> calculerChemin( Case source, Case destination )
	{
		List<Case> path = new ArrayList<Case>() ;
		
		int cptx ;
		int cpty ;
		
		if (source.getX() < destination.getX())
		{
			cptx = source.getX() + 1 ;
			while( cptx < destination.getX() )
			{
				path.add( plateau.getCasefromCoords(cptx, source.getY()) ) ;
				cptx ++ ;
			}
		}
		else
		{
			cptx = source.getX() - 1 ;
			while( cptx > destination.getX() )
			{
				path.add( plateau.getCasefromCoords(cptx, source.getY())) ;
				cptx -- ;
			}
		}
		

		
		if (source.getY() < destination.getY())
		{
			cpty = source.getY() + 1 ;
			while( cpty < destination.getY() )
			{
				path.add(plateau.getCasefromCoords(cptx, cpty)) ;
				cpty ++ ;
			}
		}
		else
		{
			cpty = source.getY() - 1 ;
			while( cpty > destination.getY() )
			{
				path.add(plateau.getCasefromCoords(cptx, cpty)) ;
				cpty -- ;
			}
		}
		
		return path ;
	}
}
